<template>
  <div id="article_details">
    <articleHead
      @clickLabel="(label)=>{$emit('clickLabel',label)}"
      :title="article.title"
      :time="getTime(article.created_at)"
      :labels="article.article_labels"
    />
    <articleHr/>
    <!-- <div class="article_details_body" ref="article_details_body" v-html="content"></div> -->
    <div class="article_details_body" ref="article_details_body" v-html="article.content"></div>
    <articleHr/>
    <articleFooter/>
  </div>
</template>
<script>
import articleHead from './components/head'
import articleFooter from './components/footer'
import articleHr from './components/hr'
import Prism from 'prismjs'
/**
 * 博文组件
 * title="标题"
 * time="日期"
 * content="内容"
 */
export default {
  name: 'article_details',
  data() {
    return {
      content:"\u003cpre class=\"language-python\"\u003e\u003ccode\u003eimport subprocess, os, time\n\nclass ExecError(Exception):\n    def __init__(self, msg):\n        self.msg = msg\n    def __str__(self):\n        try:\n            re_msg = (\"cmd exit with error return status  errmsg:%s\" % self.msg)\n        except Exception:\n            re_msg = (\"cmd exit with error return status  errmsg:%s\" % self.msg[0])\n        return re_msg\n\ndef exec_shell_cmd(cmd):\n    _pipe = subprocess.PIPE\n    obj = subprocess.Popen(cmd, stdin=_pipe,\n                           stdout=_pipe,\n                           stderr=_pipe,\n                           env=os.environ,\n                           shell=True)\n    out = obj.stdout.read(32*1024000)\n    err = obj.stderr.read()\n    result = obj.communicate()\n    obj.stdin.close()\n    _returncode = obj.returncode\n    if _returncode not in [0]:\n        if err:\n            print result\n            raise ExecError(err)\n    result = (out, \"\")\n    return result\n\ndef exec_shell_cmd_json_result(cmd):\n    ret = exec_shell_cmd(cmd)\n    if len(ret) \u0026gt; 1:\n        return ret[0].split('\\n')[:-1]\n\n\ndef execute_cmd_remote_node_result(host, cmd):\n    try:\n        exc_cmd = '''ssh -t %s \\\"source ~/.bashrc \u0026amp;\u0026amp; source ~/.bash_profile \u0026amp;\u0026amp; %s\\\"''' % (host, cmd)\n        exc_cmd = exc_cmd.replace(\" $\", \" \\$\")\n        print(time.strftime('%Y-%m-%d %H:%M:%S') + \" INFO [-] \" + \"execute_cmd_remote_node_result exc_cmd(%s) begin\" % exc_cmd)\n        result = exec_shell_cmd_json_result(exc_cmd)\n        print(time.strftime('%Y-%m-%d %H:%M:%S') + \" INFO [-] \" + \"execute_cmd_remote_node_result exc_cmd(%s) result(%s)\" % (exc_cmd, str(result)))\n    except BaseException as e:\n        print(time.strftime('%Y-%m-%d %H:%M:%S') + \" ERROR [-] \" + \"ssh base execute_cmd_remote_node_result(%s) error: %s\" % (cmd, e))\n        raise \"ssh base execute_cmd_remote_node_result(%s) error: %s\" % (cmd, e)\n    return result\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e",
    }
  },
  props: {
    article: {
      type: Object,
      required: true
    }
  },
  components: {
    articleHead,
    articleFooter,
    articleHr
  },
  methods: {
    getTime (time) {
      let { year, month, day } = this.$utils.timeConversion(time)
      return year + '-' + month + '-' + day
    }
  },
  mounted () {
    Prism.highlightAll()
  }
}
</script>
